package com.wutuo.roster.provider.dao;

import com.wutuo.roster.api.request.ListParentsRequest;
import com.wutuo.roster.api.request.ParentsRequest;
import com.wutuo.roster.api.response.ParentsResponse;
import com.wutuo.roster.provider.domain.Parents;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * 服务关系表 Dao 层
 *
 * @author lvh
 * @version 1.0
 */
public interface ParentsMapper extends BaseParentsMapper {

    @SelectProvider(type = ParentsSqlProvider.class, method = "lisForPage")
    @ResultType(value = ParentsResponse.class) List<ParentsResponse> lisForPage(
        ListParentsRequest request);

    @SelectProvider(type = ParentsSqlProvider.class, method = "list")
    @ResultType(value = ParentsResponse.class) List<ParentsResponse> list(ParentsRequest request);

    /**
     * 根据花名册删除家常关系表
     *
     * @param rosterId
     * @return int
     * @author lvh 2016年2月3日 下午12:22:57</br>
     */
    @Delete({"delete from parents where roster_id = #{rosterId,jdbcType=BIGINT}"})
    int deleteParentsByrosterId(@Param("rosterId") Long rosterId);

    @Select({"select", "id,roster_id,", "user_name,", "user_phone,", "user_type,", "create_by,",
        "create_date,", "update_by,", "update_date,", "remarks,", "del_flag", "cm_institution_id",
        "from parents", "where roster_id = #{rosterId,jdbcType=BIGINT}", "and del_flag = 1"})
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
        @Result(column = "roster_id", property = "rosterId", jdbcType = JdbcType.BIGINT),
        @Result(column = "user_name", property = "userName", jdbcType = JdbcType.VARCHAR),
        @Result(column = "user_phone", property = "userPhone", jdbcType = JdbcType.VARCHAR),
        @Result(column = "user_type", property = "userType", jdbcType = JdbcType.BIGINT),
        @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.BIGINT),
        @Result(column = "create_date", property = "createDate", jdbcType = JdbcType.DATE),
        @Result(column = "update_by", property = "updateBy", jdbcType = JdbcType.BIGINT),
        @Result(column = "update_date", property = "updateDate", jdbcType = JdbcType.DATE),
        @Result(column = "remarks", property = "remarks", jdbcType = JdbcType.VARCHAR),
        @Result(column = "cm_institution_id", property = "cmInstitutiond", jdbcType = JdbcType.BIGINT),
        @Result(column = "del_flag", property = "delFlag", jdbcType = JdbcType.VARCHAR)})
    List<Parents> listParentsByRosterId(@Param("rosterId") Long rosterId);
}